import requests
from bs4 import BeautifulSoup

stockList = []
def download(url):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
    }
    req = requests.get(url,headers=headers)
    data = req.content.decode('gb2312')
    soup = BeautifulSoup(data,'html5lib',from_encoding='gb2312')
    mytable = soup.select('#table1')
    for line in mytable[0].find_all('tr'):
        print(line.get_text()) #提取所有的 td
        print(line.select("td:nth-of-type(1)")[0].text) #针对每一个td

if __name__ == "__main__":
    url = "https://quote.stockstar.com/fund/stock.shtml"
    download(url)